package com.imooc.miaosha.myredis;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

@Configuration
public class MyJedisConfiguration {
    @Autowired
    MyRedisProperties properties;
    @Bean
    public Jedis CreateJedis(){
        return jedisPoolFactory().getResource();
    }

    private JedisPool jedisPoolFactory(){
        JedisPoolConfig config = new JedisPoolConfig();
        config.setMaxIdle(properties.getPoolMaxIdle());
        config.setMaxTotal(properties.getPoolMaxTotal());
        config.setMaxWaitMillis(properties.getPoolMaxWait()*1000);
        return new JedisPool(config,properties.getHost(),properties.getPort(),properties.getTimeout()*1000);//redis默认有16个库，从0号开始
    }

}
